<extend name="Public:base"/>

<!--侧边导航-->
<block name="aside">
    <include file="Public:aside"/>
</block>

<block name="main">

<div class="row">
    <div class="col-md-12">
    <form id="myform" name="myform" class="form-horizontal" action="{:U('Category/edit')}" method="post">
    <!-- Nav tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li class="active"><a href="#home" role="tab" data-toggle="tab">基本设置</a></li>
        <li><a href="#seo" role="tab" data-toggle="tab">SEO设置</a></li>
        <!--<li><a href="#extend" role="tab" data-toggle="tab">扩展信息</a></li>-->
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home">
            <div class="form-group">
                <label class="control-label col-md-2">上级栏目</label>
                <div class="col-md-8">
                    <div>
                        <select name="parentid" class="form-control" <?php if($vo['parentid'] == 0):?>disabled<?php endif;?>>
                            <option value="0">作为一级栏目</option>
                            {$select_categorys}
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                <label class="control-label col-md-2">栏目类型</label>
                <div class="col-md-8">
                    {:Form::select(
                    array('field'=>'modelid',
                    'options'=>$model+array('0'=>array('id'=>0,'name'=>'外部链接')),
                    'options_key'=>'id,name',
                    'setup'=>array('onchange'=>'changetemplate(this.value)')),
                    $vo['modelid']
                    )}
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2">栏目名称</label>
                <div class="col-md-8">
                    <input type="text" name="catname" class="form-control" value="{$vo['catname']}" />
                </div>
            </div>

            <?php if($_SESSION['admin']['role'] == 1):?>
            <div class="form-group type1">
                <label class="control-label col-md-2">页面命名</label>
                <div class="col-md-8">
                    <input type="text" name="catdir" class="form-control" value="{$vo['catdir']}" />
                </div>
            </div>
            <?php endif;?>

            <div class="form-group" id="model_url" style="display:none;">
                <label class="control-label col-md-2">外部链接地址</label>
                <div class="col-md-8">
                    <input type="text" name="url" class="form-control" value="<if condition="$vo['type']==2">{$vo['url']}</if>" />
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-2">栏目图片</label>
                <div class="col-md-8">
                    <div class="thumb_image">
                        <div id="image_aid_box"></div>
                        <a class="thumbnail" href="javascript:swfupload('image','{:get_yzh_auth(1,'200kb',1)}',yesdo);">
                            <img id="image_pic" height="68" src="<if condition="!empty($vo['image'])">{$vo['image']}<else/>__IMG__/upload_thumb.png</if>"></a>
                        <input type="button" value="取消图片" onclick="javascript:clean_thumb('image');" class="btn btn-xs btn-primary"/>
                        <input type="hidden" id="image" name="image" value="{$vo['image']}"/>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-2">多栏目设置: </label>
                <div class="col-md-8">
                    <div class="checkbox-inline">
                    <input type="checkbox" id="chage_all" name="chage_all" value="1" /><font color="red"> {:L('chage_all')}</font>
                    </div>
                </div>
            </div>

            <div class="form-group" >
                <label class="control-label col-md-2">导航</label>
                <div class="col-md-8">
                    {:Form::radio(array('field'=>'ismenu','options'=>array('1'=>L('yes'),'0'=>L('no'))),$vo['ismenu'])}
                </div>
            </div>

            <?php if($vo['modelid'] > 1):?>
            <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                <label class="control-label col-md-2">分页条数</label>
                <div class="col-md-8">
                    <input type="text" name="pagesize" class="form-control w-100" value="<if condition="!empty($vo['pagesize'])">{$vo['pagesize']}</if>" size="3" /> <font color="red">{:L('pagesize_desc')}</font>
                </div>
            </div>
            <?php endif;?>

            <?php if($vo['modelid'] > 0):?>
            <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                <label class="control-label col-md-2">列表页模板</label>
                <div class="col-md-8">
                    <select id="template_list" name="template_list" class="form-control w-300 pull-left"></select>
                    &nbsp;&nbsp;
                    <input type="checkbox" class="pull-left" id="listtype" name="listtype"  onclick="javascript:templatetype();" value="1"  <if condition="!empty($vo['listtype'])">checked</if> /> 是否为封面栏目
                </div>
            </div>
            <?php endif;?>
            <?php if($vo['modelid'] > 1):?>
            <div class="form-group" <?php if($_SESSION['admin']['role'] != 1):?>style="display:none;"<?php endif;?>>
                <label class="control-label col-md-2">内容页模板</label>
                <div class="col-md-8">
                    <select id="template_show" name="template_show" class="form-control w-300"></select>
                </div>
            </div>
            <?php endif;?>
        </div>

        <div role="tabpanel" class="tab-pane" id="seo">

            <div class="form-group">
                <label class="control-label col-md-2">{:L('seo_title')}</label>
                <div class="col-md-8">
                    <input name='title' type='text' value="{$vo['title']}" class="form-control">
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-2">{:L('seo_keywords')}</label>
                <div class="col-md-8">
                    <input name="keywords" type="text" value="{$vo['keywords']}" class="form-control">
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-2">{:L('seo_description')}</label>
                <div class="col-md-8">
                    <textarea name="description" rows="5" cols="60" class="form-control">{$vo['description']}</textarea>
                </div>
            </div>
        </div>

        <!--<div role="tabpanel" class="tab-pane" id="extend">
            <div class="form-group">
                <label class="control-label col-md-2">英文标题</label>
                <div class="col-md-8">
                    <input name="wap_catname" type="text" value="{$vo['wap_catname']}" class="form-control">
                </div>
            </div>
        </div>-->

        <div class="form-actions">
            <input type="hidden" name="id" value="{$vo.id}">
            <input type="submit" value="提交" class="btn btn-primary" >
            <button class="btn btn-default return" onclick="javascript:history.back(-1);return false;">返回</button>
        </div>
    </form>

    </div>
</div>

</block>

<block name="script">
<script type="text/javascript">
$(document).ready(function() {
    $('#myform').ajaxForm({
        success:  complete,  // post-submit callback
        dataType: 'json'
    });
});

function complete(data){
    if(data.status==1){
        layer.msg(data.info, {
            icon: 1,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        }, function(){
            window.location.href = "{$Think.cookie.__forward__}";
            return true;
        });
    }else{
        layer.msg(data.info, {
            icon: 2,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        });
    }

}
</script>
<script>

var modulearr = new Array();

<volist name="model" id="mdate">
modulearr[{$mdate['id']}] = "{$mdate['tablename']}";
</volist>

var templatearr = new Array();

<volist name="templates" id="tem">
templatearr[{$i}] = "{$tem['name']},{$tem['value']},{$tem['filename']}";
</volist>


var datas = "<option value=''>请选择</option>";
var modelid = $('#modelid').val();


showtemplist({$vo['modelid']},<if condition="empty($vo[listtype])">0<else />{$vo.listtype}</if>);

function showtemplist(m,t){

    var type='_list';

    if(t){
        type='_index';
    }

    var mtlist = modulearr[m]+type;
    var mtshow = modulearr[m]+'_show';

    if(modulearr[m]=='Page')
        mtlist=mtshow ='Page_';

    $('#template_list').html(datas);
    $('#template_show').html(datas);

    listdatas = showdatas ='';

    for(i=1;i<templatearr.length;i++){
        data = templatearr[i].split(',');

        if(data[0].indexOf(mtlist)  >= 0){
            listdatas  ="<option value='"+data[1]+"'>"+data[2]+"</option>";
            $('#template_list').append(listdatas);
        }

        if(data[0].indexOf(mtshow)  >= 0){
            showdatas ="<option value='"+data[1]+"'>"+data[2]+"</option>";
            $('#template_show').append(showdatas);
        }
    }
    $('#template_list').val('{$vo.template_list}');
    $('#template_show').val('{$vo.template_show}');
}

function changetemplate(m){
    if(m==0){
        $('#model_url').show();
        $('.type1').hide();
        $('#type').val('2');
        $('#catdir').removeClass('required');
    }else{
        $('#model_url').hide();
        $('.type1').show();
        $('#type').val('0');
        $('#catdir').addClass('required');
    }
    showtemplist(m,0);
    $("#listtype").removeAttr("checked");
}

function templatetype(){

    var modelid = $('#modelid').val();

    if($("#listtype").attr('checked')=='checked'){
        showtemplist(modelid,1);
    }else{
        showtemplist(modelid,0);
    }

}

function urlrule(m){
    if(m==1){
        $('#urlrule').show();
    }else{
        $('#urlrule').hide();
    }
}

urlrule({$vo['ishtml']});

<if condition="$vo['type'] eq 2">
    $('#modelid').val(0);
    changetemplate(0);
</if>
</script>
</block>